package com.zzx.bms.controller;

import com.zzx.bms.core.util.Page;
import com.zzx.bms.domain.Nursestation;
import com.zzx.bms.domain.Nursestation;
import com.zzx.bms.domain.Role;
import com.zzx.bms.domain.User;
import com.zzx.bms.service.INursestationService;
import com.zzx.bms.service.INursestationService;
import com.zzx.bms.service.IRoleService;
import com.zzx.bms.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SamZhao on 2016/12/6.
 */
@Controller
@RequestMapping("/nursestation")
public class NursestationController {

    private static Logger logger = Logger.getLogger(NursestationController.class);

    @Autowired
    private INursestationService nursestationService;

    @RequestMapping("/list")
    public String nursestationList(Nursestation nursestation, Model model) throws Exception {

        List<Nursestation> nurlist = nursestationService.findAllNursestationList();
        model.addAttribute("nurlist", nurlist);

        return "nursestation/nursestationList";
    }

    @RequestMapping(value = "/addNursestation")
    public String addNursestation(Model model){
        return "nursestation/addNursestation";
    }

    @RequestMapping("/saveNursestation")
    public @ResponseBody String saveNursestation(Nursestation nursestation) throws Exception {
        int flag = nursestationService.saveNursestation(nursestation);
        if(flag > 0)
            return "success";
        else
            return "fail";
    }

    @RequestMapping("/deleteNursestation")
    public @ResponseBody String deleteNursestation(Nursestation nursestation, String id) throws Exception {
        int flag = nursestationService.deleteNursestationById(id);
        if(flag > 0)
            return "success";
        else
            return "fail";
    }

    @RequestMapping(value = "/checkNursestation")
    public @ResponseBody String checkNursestation(Model model, Nursestation nursestation){
        int flag = nursestationService.checkNursestation(nursestation);
        if(flag > 0)
            return "success";
        else
            return "fail";
    }

    @RequestMapping(value = "/editNursestation")
    public String editNursestation(Model model, String id){
        Nursestation nursestation = nursestationService.findNursestationById(id);
        model.addAttribute("nursestation", nursestation);
        return "nursestation/editNursestation";
    }

}
